
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/vector/vector_integration.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:29:13 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Applications of Vector Integrals &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="vector_integration.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Essential Classes in sympy.vector (docstrings)" href="api/classes.html" />
    <link rel="prev" title="General examples of usage" href="examples.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="api/classes.html" title="Essential Classes in sympy.vector (docstrings)"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="examples.html" title="General examples of usage"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Vector</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Applications of Vector Integrals</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="applications-of-vector-integrals">
<h1>Applications of Vector Integrals<a class="headerlink" href="#applications-of-vector-integrals" title="Permalink to this headline">¶</a></h1>
<p>To integrate a scalar or vector field over a region, we have to first define a region. SymPy provides three methods for defining a region:</p>
<ol class="arabic simple">
<li><p>Using Parametric Equations with <a class="reference internal" href="api/classes.html#sympy.vector.parametricregion.ParametricRegion" title="sympy.vector.parametricregion.ParametricRegion"><code class="xref py py-class docutils literal notranslate"><span class="pre">ParametricRegion</span></code></a>.</p></li>
<li><p>Using Implicit Equation with <a class="reference internal" href="api/classes.html#sympy.vector.implicitregion.ImplicitRegion" title="sympy.vector.implicitregion.ImplicitRegion"><code class="xref py py-class docutils literal notranslate"><span class="pre">ImplicitRegion</span></code></a>.</p></li>
<li><p>Using objects of geometry module.</p></li>
</ol>
<p>The <a class="reference internal" href="api/vectorfunctions.html#sympy.vector.integrals.vector_integrate" title="sympy.vector.integrals.vector_integrate"><code class="xref py py-func docutils literal notranslate"><span class="pre">vector_integrate()</span></code></a> function is used to integrate scalar or vector field over any type of region. It automatically determines the type of integration (line, surface, or volume) depending on the nature of the object.</p>
<p>We define a coordinate system and make necesssary imports for examples.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">exp</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">CoordSys3D</span><span class="p">,</span> <span class="n">ParametricRegion</span><span class="p">,</span> <span class="n">ImplicitRegion</span><span class="p">,</span> <span class="n">vector_integrate</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">r</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">theta</span><span class="p">,</span> <span class="n">phi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">CoordSys3D</span><span class="p">(</span><span class="s1">&#39;C&#39;</span><span class="p">)</span>
</pre></div>
</div>
<section id="calculation-of-perimeter-surface-area-and-volume">
<h2>Calculation of Perimeter, Surface Area, and Volume<a class="headerlink" href="#calculation-of-perimeter-surface-area-and-volume" title="Permalink to this headline">¶</a></h2>
<p>To calculate the perimeter of a circle, we need to define it. Let’s define it using its parametric equation.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">param_circle</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="mi">4</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="mi">4</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span>
</pre></div>
</div>
<p>We can also define a circle using its implicit equation.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">implicit_circle</span> <span class="o">=</span> <span class="n">ImplicitRegion</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">4</span><span class="p">)</span>
</pre></div>
</div>
<p>The perimeter of a figure is equal to the absolute value of its integral over a unit scalar field.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">param_circle</span><span class="p">)</span>
<span class="go">8*pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">implicit_circle</span><span class="p">)</span>
<span class="go">4*pi</span>
</pre></div>
</div>
<p>Suppose a user wants to calculate the perimeter of a triangle. Determining the parametric representation of a triangle can be difficult. Instead, the user can use an object of <a class="reference internal" href="../geometry/polygons.html#sympy.geometry.polygon.Polygon" title="sympy.geometry.polygon.Polygon"><code class="xref py py-class docutils literal notranslate"><span class="pre">Polygon</span></code></a> class in the geometry module.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.geometry</span> <span class="kn">import</span> <span class="n">Point</span><span class="p">,</span> <span class="n">Polygon</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">triangle</span> <span class="o">=</span> <span class="n">Polygon</span><span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">triangle</span><span class="p">)</span>
<span class="go">sqrt(5) + sqrt(13) + 4</span>
</pre></div>
</div>
<p>To define a solid sphere, we need to use three parameters (r, theta and phi). For <a class="reference internal" href="api/classes.html#sympy.vector.parametricregion.ParametricRegion" title="sympy.vector.parametricregion.ParametricRegion"><code class="xref py py-class docutils literal notranslate"><span class="pre">ParametricRegion</span></code></a> obextj, the order of limits determine the sign of the integral.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">solidsphere</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span><span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">)),</span>
<span class="gp">... </span>                            <span class="p">(</span><span class="n">phi</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pi</span><span class="p">),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">),</span> <span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">solidsphere</span><span class="p">)</span>
<span class="go">36*pi</span>
</pre></div>
</div>
</section>
<section id="calculation-of-mass-of-a-body">
<h2>Calculation of mass of a body<a class="headerlink" href="#calculation-of-mass-of-a-body" title="Permalink to this headline">¶</a></h2>
<p>Consider a triangular lamina 𝑅  with vertices (0,0), (0, 5), (5,0) and with density <span class="math notranslate nohighlight">\(\rho(x, y) = xy\:kg/m^2\)</span>. Find the total mass.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">triangle</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">5</span> <span class="o">-</span> <span class="n">x</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">triangle</span><span class="p">)</span>
<span class="go">625/24</span>
</pre></div>
</div>
<p>Find the mass of a cylinder centered on the z-axis which has height h, radius a, and density <span class="math notranslate nohighlight">\(\rho = x^2 + y^2\:kg/m^2\)</span>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">h</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a h&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cylinder</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">r</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">z</span><span class="p">),</span>
<span class="gp">... </span>                    <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">),</span> <span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">h</span><span class="p">),</span> <span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">cylinder</span><span class="p">)</span>
<span class="go">pi*a**4*h/2</span>
</pre></div>
</div>
</section>
<section id="calculation-of-flux">
<h2>Calculation of Flux<a class="headerlink" href="#calculation-of-flux" title="Permalink to this headline">¶</a></h2>
<p>1. Consider a region of space in which there is a constant vectorfield
<span class="math notranslate nohighlight">\(E(x, y, z) = a\mathbf{\hat{k}}\)</span>.
A  hemisphere of radius r  lies on the x-y plane. What is the flux of the field through the sphere?</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">semisphere</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">)),</span>\
<span class="gp">... </span>                            <span class="p">(</span><span class="n">phi</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">flux</span> <span class="o">=</span> <span class="n">vector_integrate</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">semisphere</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">flux</span>
<span class="go">pi*a*r**2</span>
</pre></div>
</div>
<p>2. Consider  a  region  of  space  in  which  there  is  a  vector  field
<span class="math notranslate nohighlight">\(E(x, y, z) = x^2 \mathbf{\hat{k}}\)</span> above the x-y plane, and a field
<span class="math notranslate nohighlight">\(E(x, y, z) = y^2 \mathbf{\hat{k}}\)</span> below the x-y plane. What is the flux of that vector field through a cube of side length L with its center at the origin?”</p>
<p>The field is parallel to the z-axis so only the top and bottom face of the box will contribute to flux.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">L</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;L&#39;</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">top_face</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="o">-</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="o">-</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bottom_face</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="o">-</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="o">-</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="o">-</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">flux</span> <span class="o">=</span> <span class="n">vector_integrate</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">top_face</span><span class="p">)</span> <span class="o">+</span> <span class="n">vector_integrate</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">bottom_face</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">flux</span>
<span class="go">L**4/6</span>
</pre></div>
</div>
</section>
<section id="verifying-stoke-s-theorem">
<h2>Verifying Stoke’s Theorem<a class="headerlink" href="#verifying-stoke-s-theorem" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference external" href="https://en.wikipedia.org/wiki/Stokes%27_theorem">https://en.wikipedia.org/wiki/Stokes%27_theorem</a></p>
<dl>
<dt>Example 1</dt><dd><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">curl</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">curve</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">surface</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">r</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)),</span> <span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">F</span> <span class="o">=</span> <span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">C</span><span class="o">.</span><span class="n">z</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">k</span> <span class="o">+</span> <span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">k</span>
<span class="go">&gt;&gt;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">F</span><span class="p">,</span> <span class="n">curve</span><span class="p">)</span>
<span class="go">-pi/4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">curl</span><span class="p">(</span><span class="n">F</span><span class="p">),</span> <span class="n">surface</span><span class="p">)</span>
<span class="go">-pi/4</span>
</pre></div>
</div>
</dd>
<dt>Example 2</dt><dd><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">circle</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cone</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">r</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="p">),</span> <span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cone</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">r</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="p">),</span> <span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="o">**</span><span class="mi">3</span><span class="o">/</span><span class="mi">3</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="p">))</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span><span class="o">/</span><span class="mi">3</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="p">))</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">z</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">f</span><span class="p">,</span>  <span class="n">circle</span><span class="p">)</span>
<span class="go">pi/2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">curl</span><span class="p">(</span><span class="n">f</span><span class="p">),</span>  <span class="n">cone</span><span class="p">)</span>
<span class="go">pi/2</span>
</pre></div>
</div>
</dd>
</dl>
</section>
<section id="verifying-divergence-theorem">
<h2>Verifying Divergence Theorem<a class="headerlink" href="#verifying-divergence-theorem" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference external" href="https://en.wikipedia.org/wiki/Divergence_theorem">https://en.wikipedia.org/wiki/Divergence_theorem</a></p>
<dl>
<dt>Example 1</dt><dd><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.vector</span> <span class="kn">import</span> <span class="n">divergence</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sphere</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="mi">4</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span><span class="mi">4</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="mi">4</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">)),</span>
<span class="gp">... </span>                        <span class="p">(</span><span class="n">phi</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pi</span><span class="p">),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">solidsphere</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span><span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">)),</span>
<span class="gp">... </span>    <span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">),(</span><span class="n">phi</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pi</span><span class="p">),</span> <span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">field</span> <span class="o">=</span> <span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="o">**</span><span class="mi">3</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="n">C</span><span class="o">.</span><span class="n">z</span><span class="o">**</span><span class="mi">3</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">field</span><span class="p">,</span> <span class="n">sphere</span><span class="p">)</span>
<span class="go">12288*pi/5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">divergence</span><span class="p">(</span><span class="n">field</span><span class="p">),</span> <span class="n">solidsphere</span><span class="p">)</span>
<span class="go">12288*pi/5</span>
</pre></div>
</div>
</dd>
<dt>Example 2</dt><dd><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cube</span> <span class="o">=</span> <span class="n">ParametricRegion</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">field</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="mi">3</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">x</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">j</span> <span class="o">+</span> <span class="n">C</span><span class="o">.</span><span class="n">z</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">x</span> <span class="o">+</span> <span class="n">C</span><span class="o">.</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="n">C</span><span class="o">.</span><span class="n">k</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">vector_integrate</span><span class="p">(</span><span class="n">divergence</span><span class="p">(</span><span class="n">field</span><span class="p">),</span> <span class="n">cube</span><span class="p">)</span>
<span class="go">-E + 7/2 + E*(-1 + E)</span>
</pre></div>
</div>
</dd>
</dl>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Applications of Vector Integrals</a><ul>
<li><a class="reference internal" href="#calculation-of-perimeter-surface-area-and-volume">Calculation of Perimeter, Surface Area, and Volume</a></li>
<li><a class="reference internal" href="#calculation-of-mass-of-a-body">Calculation of mass of a body</a></li>
<li><a class="reference internal" href="#calculation-of-flux">Calculation of Flux</a></li>
<li><a class="reference internal" href="#verifying-stoke-s-theorem">Verifying Stoke’s Theorem</a></li>
<li><a class="reference internal" href="#verifying-divergence-theorem">Verifying Divergence Theorem</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="examples.html"
                        title="previous chapter">General examples of usage</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="api/classes.html"
                        title="next chapter">Essential Classes in sympy.vector (docstrings)</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/vector/vector_integration.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="api/classes.html" title="Essential Classes in sympy.vector (docstrings)"
             >next</a> |</li>
        <li class="right" >
          <a href="examples.html" title="General examples of usage"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Vector</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Applications of Vector Integrals</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/vector/vector_integration.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:29:13 GMT -->
</html>